import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class ArcBannerImage extends StatelessWidget {
  ArcBannerImage();

  @override
  Widget build(BuildContext context) {
    var screenWidth = MediaQuery.of(context).size.width;

    return ClipPath(
      clipper: ArcClipper(),
      child: Container(
        padding: new EdgeInsets.only(left: 15.0, right: 15.0, top: 30.0),
        child: new Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[Icon(Icons.settings, color: Colors.white70, size: 25.0)],
        ),
        width: screenWidth,
        height: ScreenUtil().setHeight(400),
        decoration: new BoxDecoration(
          color: Colors.blue,
          gradient: new LinearGradient(
            begin: const FractionalOffset(0.5, 0.0),
            end: const FractionalOffset(0.5, 1.0),
            colors: <Color>[Colors.blueAccent, Colors.blue],
          ),
        ),
      ),
    );
  }
}

class ArcClipper extends CustomClipper<Path> {
  final int radiusHeight = 40;

  @override
  Path getClip(Size size) {
    // 路径
    var path = Path();
    // 设置路径的开始点
    path.lineTo(0, 0);
    path.lineTo(0, size.height - radiusHeight);

    // 设置曲线的开始样式
    var firstControlPoint = Offset(size.width / 2, size.height + radiusHeight);
    // 设置曲线的结束样式
    var firstEndPont = Offset(size.width, size.height - radiusHeight);
    // 把设置的曲线添加到路径里面
    path.quadraticBezierTo(
        firstControlPoint.dx, firstControlPoint.dy, firstEndPont.dx, firstEndPont.dy);

    // 设置路径的结束点
    path.lineTo(size.width, size.height - radiusHeight);
    path.lineTo(size.width, 0);

    // 返回路径
    return path;
  }

  @override
  bool shouldReclip(CustomClipper<Path> oldClipper) => true;
}
